package com.eduhzy.ttw.teacher.mvp.ui.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;

import com.alibaba.android.arouter.facade.annotation.Autowired;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.eduhzy.ttw.commonres.utils.RxUtil;
import com.eduhzy.ttw.commonsdk.core.Constants;
import com.eduhzy.ttw.commonsdk.core.RouterHub;
import com.eduhzy.ttw.commonsdk.entity.ClassDetailsData;
import com.eduhzy.ttw.teacher.R;
import com.eduhzy.ttw.teacher.di.component.DaggerUpdateClassComponent;
import com.eduhzy.ttw.teacher.di.module.UpdateClassModule;
import com.eduhzy.ttw.teacher.mvp.contract.UpdateClassContract;
import com.eduhzy.ttw.teacher.mvp.presenter.UpdateClassPresenter;
import com.jess.arms.base.BaseActivity;
import com.jess.arms.di.component.AppComponent;
import com.jess.arms.utils.ArmsUtils;
import com.qmuiteam.qmui.widget.dialog.QMUITipDialog;
import com.qmuiteam.qmui.widget.roundwidget.QMUIRoundButton;
import com.xw.repo.XEditText;

import butterknife.BindView;
import butterknife.OnClick;

import static com.jess.arms.utils.Preconditions.checkNotNull;

/**
 * @author xubo
 * @date 2018-9-26 12:02:28
 */
@Route(path = RouterHub.APP_UPDATECLASSACTIVITY)
public class UpdateClassActivity extends BaseActivity<UpdateClassPresenter> implements UpdateClassContract.View {
    @Autowired(name = Constants.ROUTER_DATA)
    ClassDetailsData mData;
    @BindView(R.id.class_name)
    XEditText mClassName;
    @BindView(R.id.btn_exit)
    QMUIRoundButton mBtnExit;

    @Override
    public void setupActivityComponent(@NonNull AppComponent appComponent) {
        //如找不到该类,请编译一下项目
        DaggerUpdateClassComponent
                .builder()
                .appComponent(appComponent)
                .updateClassModule(new UpdateClassModule(this))
                .build()
                .inject(this);
    }

    @Override
    public int initView(@Nullable Bundle savedInstanceState) {
        //如果你不需要框架帮你设置 setContentView(id) 需要自行设置,请返回 0
        return R.layout.activity_update_class;
    }

    @Override
    public void initData(@Nullable Bundle savedInstanceState) {
        mBtnExit.setChangeAlphaWhenPress(true);
        mClassName.setText(mData.getBjmc());
    }

    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }

    @Override
    public void showMessage(@NonNull String message) {
        checkNotNull(message);
        RxUtil.showTipDialog(getActivity(), QMUITipDialog.Builder.ICON_TYPE_NOTHING, message);
    }

    @Override
    public void launchActivity(@NonNull Intent intent) {
        checkNotNull(intent);
        ArmsUtils.startActivity(intent);
    }

    @Override
    public void killMyself() {
        finish();
    }

    @Override
    public Activity getActivity() {
        return this;
    }


    @OnClick(R.id.btn_exit)
    public void onViewClicked() {
        if (RxUtil.showEditTip(this, mClassName, "请输入班级名称")) {
            return;
        }
        mPresenter.updateClassInfo(mData.getId(),mClassName.getText().toString(),mData.getNjbm());
    }
}
